package fs

import (
	fs2 "io/fs"
	"os"
	"path/filepath"
)

type LocalFS struct {
	dir string
}

type localFile struct {
	f *os.File
}

func (lf localFile) Stat() (fs2.FileInfo, error) {
	return lf.f.Stat()
}
func (lf localFile) Read(byte []byte) (int, error) {
	return lf.f.Read(byte)
}
func (lf localFile) Close() error {
	return lf.f.Close()
}

func NewLocalFS(dir string) LocalFS {
	return LocalFS{
		dir: dir,
	}
}
func (l LocalFS) Open(name string) (fs2.File, error) {
	f, e := os.Open(filepath.Join(l.dir, name))
	if e != nil {
		return nil, e
	}
	return localFile{f: f}, nil
}
